<!--
~ Copyright 2018-present Open Networking Foundation
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~     http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<div id="ov-device">
    <onos-loading [theme]="'light'" [running]="loadingIconShown"></onos-loading>
    <div class="tabular-header">
        <h2>Devices ({{ tableData.length }} total)</h2>
        <div class="ctrl-btns">
            <div class="refresh" (click)="toggleRefresh()">
                <!-- See icon.theme.css for the defintions of the classes active and refresh-->
                <onos-icon classes="{{ autoRefresh?'active refresh':'refresh' }}" iconId="refresh" iconSize="42" toolTip="{{ autoRefreshTip }}"></onos-icon>
            </div>
            <div class="separator"></div>

            <div>
                <onos-icon classes="{{ selId ? 'current-view':undefined }}" iconId="deviceTable" iconSize="42"></onos-icon>
            </div>

            <div (click)="navto('/flow')">
                <onos-icon classes="{{ selId ? 'active-rect' :undefined}}" iconId="flowTable" iconSize="42" toolTip="{{ flowTip }}"></onos-icon>
            </div>

            <div (click)="navto('/port')">
                <onos-icon classes="{{ selId ? 'active-rect' :undefined}}" iconId="portTable" iconSize="42" toolTip="{{ portTip }}"></onos-icon>
            </div>

            <div (click)="navto('/group')">
                <onos-icon classes="{{ selId ? 'active-rect' :undefined}}" iconId="groupTable" iconSize="42" toolTip="{{ groupTip }}"></onos-icon>
            </div>

            <div (click)="navto('/meter')">
                <onos-icon classes="{{ selId ? 'active-rect' :undefined}}" iconId="meterTable" iconSize="42" toolTip="{{ meterTip }}"></onos-icon>
            </div>

            <div (click)="navto('/pipeconf')">
                <onos-icon classes="{{ selId ? 'active-rect' :undefined}}" iconId="pipeconfTable" iconSize="42" toolTip="{{ pipeconfTip }}"></onos-icon>
            </div>
        </div>
        <div class="search">
            <input id="searchinput" [(ngModel)]="tableDataFilter.queryStr" type="search" #search placeholder="Search" />
            <select [(ngModel)]="tableDataFilter.queryBy">
                <option value="" disabled>Search By</option>
                <option value="$">All Fields</option>
                <option value="id">Device-Id</option>
                <option value="name">Name</option>
                <option value="protocol">Protocol</option>
            </select>
        </div>
    </div>

    <div id="summary-list" class="summary-list" onosTableResize>
        <div class="table-header">
            <table>
                <tr>
                    <td colId="available" class="table-icon"></td>
                    <td colId="type" class="table-icon"></td>
                    <td colId="name" (click)="onSort('name')">Friendly Name
                        <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('name')"></onos-icon>
                    </td>
                    <td colId="id" (click)="onSort('id')">Device ID
                        <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('id')"></onos-icon>
                    </td>
                    <td colId="masterid" [ngClass]="{width: '130px'}" (click)="onSort('masterid')">Master
                        <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('masterid')"></onos-icon>
                    </td>
                    <td colId="num_ports" [ngClass]="{width: '70px'}" (click)="onSort('num_ports')">Ports
                        <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('num_ports')"></onos-icon>
                    </td>
                    <td colId="mfr" (click)="onSort('mfr')">Vendor
                        <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('mfr')"></onos-icon>
                    </td>
                    <td colId="hw" (click)="onSort('hw')">H/W Version
                        <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('hw')"></onos-icon>
                    </td>
                    <td colId="sw" (click)="onSort('sw')">S/W Version
                        <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('sw')"></onos-icon>
                    </td>
                    <td colId="protocol" [ngClass]="{width: '100px'}" (click)="onSort('protocol')">Protocol
                        <onos-icon classes="active-sort" [iconSize]="10" [iconId]="sortIcon('protocol')"></onos-icon>
                    </td>
                </tr>
            </table>
        </div>
        <div class="table-body">
            <table>
                <tr class="table-body" *ngIf="tableData.length === 0" class="no-data">
                    <td colspan="9">{{ annots.noRowsMsg }}</td>
                </tr>
                <tr *ngFor="let dev of tableData | filter : tableDataFilter" (click)="selectCallback($event, dev)" [ngClass]="{selected: dev.id === selId, 'data-change': isChanged(dev.id)}">
                    <td class="table-icon">
                        <onos-icon classes="{{ dev._iconid_available}}" iconId={{dev._iconid_available}}></onos-icon>
                    </td>
                    <td class="table-icon">
                        <onos-icon classes="{{dev._iconid_type? 'active-type':undefined}}" iconId="{{dev._iconid_type}}"></onos-icon>
                    </td>
                    <td>{{ dev.name }}</td>
                    <td>{{ dev.id }}</td>
                    <td>{{ dev.masterid }}</td>
                    <td>{{ dev.num_ports }}</td>
                    <td>{{ dev.mfr }}</td>
                    <td>{{ dev.hw }}</td>
                    <td>{{ dev.sw }}</td>
                    <td>{{ dev.protocol }}</td>
                </tr>
            </table>
        </div>
    </div>

    <onos-devicedetails class="floatpanels" id="{{ selId }}" (closeEvent)="deselectRow($event)"></onos-devicedetails>
</div>
